Thread: undefined reference to `___ashrsi3'

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    4

    undefined reference to `___ashrsi3'

    Hey guys, I need some help. Does anyone have any clue what the linker error

    undefined reference to `___ashrsi3'

    refers to? It seems like it involves the math library libm.a, but linking with -lm doesn't help, nor does #include <math.h>

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably forgot to define a function named ashrsi3 (or something like that).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Where's the source code?

    Is it something you wrote (post it), or some random thing you downloaded off the web (URL).

    Note however, that we're not a "please fix this code I found on the web" site.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2014
    Posts
    4
    Source code:

    Code:
    #include <sgl.h>
    #include "main.h"
    #include <sega_sys.h>
    
    
    #define NoSprites 2
    
    
    extern PICTURE pic_spr[];
    
    
    void load_sprite(PICTURE *pcptr, Uint32 NbPicture) {
    
        TEXTURE *txptr ;
    
        for(; NbPicture-- > 0 ; pcptr++){
            txptr = tex_spr + pcptr->texno ;
            slDMACopy(pcptr->pcsrc, 
            (void *)(SpriteVRAM + ((txptr->CGadr) << 3)), 
            (txptr->Hsize * txptr->Vsize * 4) >> (pcptr->cmode)) ;
        }
    }
    
    FIXED tpos[] = {toFIXED(0), toFIXED(0), toFIXED(0), toFIXED(0)};
    
    
    SPR_ATTR tattr[] = {
    
        SPR_ATTRIBUTE(0, No_Palet, No_Gouraud, CL32KRGB, sprNoflip)
    
    };
    
    
    void ss_main(void) {
    
    
        ANGLE ang = DEGtoANG(0.0);
    
        slInitSystem(TV_320x240, tex_spr, 1);
    
        load_sprite(pic_spr, NoSprites);
    
        slColRAMMode(CRM16_1024);        
        
        slBack1ColSet((void*)BACK_COL_ADR, (Uint16)0);      
    
        while(1) {
    
            slDispSprite(tpos, tattr, ang);
    
            slPrint("WTF? YO?", slLocate(1, 1));
    
            slSynch();
    
        }
    }
    It's for a SEGA Saturn. I was just curious if anyone could point me in the right direction as how to go about solving this. I'm not looking for someone to do this for me. I've been trying to find a clue to this literally all day, and I'm only asking for help because I'm out of ideas. I just thought someone else might've worked on something and had the same error, meaning this might be a common issue, not just related to the Saturn libraries.

    I took part of this code from a similar program that gets the exact same errors when I try to compile that one. The error seems to come from the load_sprite function, because when I comment it out, the error goes away. The code is necessary to show the sprite on-screen, though. The program I took this from had been compiled by someone else and worked, and another tutorial file backs the code up, so I'm confident it isn't the source code, it's how it's being compiled. I was kinda wondering if maybe ashrsi was present in an old version of libm.a, and has been removed.

    You probably forgot to define a function named ashrsi3 (or something like that).
    The function isn't in the source code. The compiler says there's a linker error. I looked this error up, and I found a site (in Japanese ) that seems to have solved the issue, and all I could really gather was to link with libm.a with -lm.
    Last edited by aeroflotte; 11-24-2014 at 02:33 AM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by aeroflotte
    all I could really gather was to link with libm.a with -lm.
    You probably read a thread where someone had problems trying to use a function declared in <math.h> when compiling with a compiler that did not automatically link to the math component of the C standard library implementation. Under these circumstances -lm is the appropriate solution. In your case though, you have a similiar problem, but it is not the same: you need to find out what is the library to link to, and that usually means reading relevant documentation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2014
    Posts
    4
    Thanks, you gave me a great idea and I followed it and solved my problem. The library I had that was made for Unix lacked the necessary files, so I looked at the Windows libraries and found what I needed. Compiles just fine!

  7. #7
    Registered User Al3's Avatar
    Join Date
    Nov 2014
    Posts
    135
    I think ashrsi3.c is the exact library that contains this scalar function. But this is compiled from linux I don't know whats your deal with it.
    There is a manual linker as a setting of your compiler, try it.

    EDIT: Nevermind haha.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Just out-of-curiosity how a library made for Windows installed just fine on UNIX?

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think it was made for both, but the particular package for Unix that aeroflotte was missing something (a makefile of some sort, perhaps?)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by laserlight View Post
    I think it was made for both, but the particular package for Unix that aeroflotte was missing something (a makefile of some sort, perhaps?)
    Gotcha!

  11. #11
    Registered User
    Join Date
    Nov 2014
    Posts
    4
    It works on both platforms, only the one that was made to be more Unix friendly didn't have all the libraries and header files that the original had.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined reference to
    By diego in forum C++ Programming
    Replies: 4
    Last Post: 05-18-2010, 03:06 PM
  2. Help! Undefined Reference
    By halo3 in forum C++ Programming
    Replies: 10
    Last Post: 08-25-2009, 12:43 PM
  3. Undefined reference
    By TheEngineer in forum C Programming
    Replies: 17
    Last Post: 08-12-2009, 10:34 AM
  4. undefined reference
    By B_Love in forum C++ Programming
    Replies: 6
    Last Post: 09-26-2005, 08:13 AM
  5. Undefined reference
    By Buckshot in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 03:28 PM